package gyb.rasa.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import gyb.rasa.common.utils.JwtUtil;
import gyb.rasa.common.utils.Result;
import gyb.rasa.entity.MessageReceived;
import gyb.rasa.entity.vo.HotQuestion;
import gyb.rasa.service.MessageReceivedService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 郜宇博
 * @since 2023-04-02
 */
@RestController
@RequestMapping("/api")
public class MessageReceivedController {
    private final MessageReceivedService messageReceivedService;

    public MessageReceivedController(MessageReceivedService messageReceivedService) {
        this.messageReceivedService = messageReceivedService;
    }

    @ApiOperation("获取HotQuestion格式的问答")
    @RequestMapping("getQuestion")
    public Result getQuestionByMid(@RequestParam("mid") Integer mid) {
        HotQuestion question = messageReceivedService.getMessageReceiveTransformHotQuestion(mid);
        return Result.ok().data("question", question);
    }

    @ApiOperation("获取最佳回复")
    @GetMapping("goodResponses")
    public Result getGoodResponses(@RequestParam("count") Integer count) {
        List<HotQuestion> goodResponseList = messageReceivedService.getGoodResponses(count);
        return Result.ok().data("goodResponseList", goodResponseList);
    }
    @ApiOperation("根据uid获取所有message")
    @GetMapping("messagesByUid/{current}/{limit}/{uid}")
    public Result getMessagesByUid(@ApiParam(name = "current", value = "当前页码",required = true) @PathVariable Long current,
                                   @ApiParam(name = "limit", value = "一页记录数",required = true) @PathVariable Long limit,
                                   @ApiParam(name = "uid", value = "用户id",required = true) @PathVariable Integer uid,
                                   HttpServletRequest httpServletRequest) {
        IPage<MessageReceived> messageList = messageReceivedService.getMessageByUid(current,limit, uid,httpServletRequest);
        return Result.ok().data("messageList",messageList);
    }
}

